package com.dc.service;

import com.dc.constant.MessageConstant;
import com.dc.dao.WorkflowElectricBoxDao;
import com.dc.entity.ShipRepairEntity;
import com.dc.entity.WorkflowElectricBoxEntity;
import com.dc.exception.ServiceException;
import com.dc.model.AjaxResult;
import com.dc.service.dto.WorkflowElectricBoxDto;
import com.dc.service.dto.WorkflowPowerDto;
import com.dc.service.dto.electronic.HttpGetPowerReturnNewBody;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class WorkflowElectricService {

    @Resource
    private HttpService2 httpService2;

    @Resource
    private WorkflowElectricBoxDao workflowElectricBoxDao;

    public List<WorkflowPowerDto> syncChildPower(Set<String> mfids, Date enterTime, Date outTime ) {

        // mfid, power
        List<WorkflowPowerDto> result = new ArrayList<>();

        Map<String, HttpGetPowerReturnNewBody> powerMapByHourType = httpService2.getPowerListByHourType(mfids, enterTime, outTime);

        for (Map.Entry<String, HttpGetPowerReturnNewBody> entry : powerMapByHourType.entrySet()) {
            double power = 0.;
            HttpGetPowerReturnNewBody body = entry.getValue();
            if(ObjectUtils.isNotEmpty(body)) {
                power = body.getSum();
            }

            WorkflowPowerDto dto = new WorkflowPowerDto(entry.getKey(), power);
            result.add(dto);
        }

        return result;

    }

}
